package com.shen.accountbook.module.home.booknote;

import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shen.accountbook.R;
import com.shen.accountbook.bean.temp.ThirdSortBean;
import com.shen.accountbook.module.base.BaseHolder;
import com.shen.accountbook.utils.ResUtils;

import butterknife.BindView;

/**
 * author:  shen
 * date:    2018/9/13
 */
public class BookNoteHolder extends BaseHolder<ThirdSortBean> {

    @BindView(R.id.item_tb_type_img)
    ImageView mIvTbType;
    @BindView(R.id.item_tb_type_tv)
    TextView mTvTbType;

    BookNoteAdapter.ItemClickListener mListener;
    BookNoteAdapter mAdapter;

    public BookNoteHolder(@NonNull View itemView, Context context, BookNoteAdapter adapter, BookNoteAdapter.ItemClickListener listener) {
        super(itemView, context);
        mListener = listener;
        mAdapter = adapter;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindView(final ThirdSortBean bean, int position) {
        mTvTbType.setText(bean.getThird_sort_name());
        if(mAdapter.mContext.mSelectThirdId == bean.getThird_sort_id()){
            mTvTbType.setTextColor(ResUtils.getColor(R.color.main_tone));
            mTvTbType.setBackground(ResUtils.getDrawable(R.drawable.shape_tv_bg_blue));
        }else {
            mTvTbType.setTextColor(ResUtils.getColor(R.color.black));
            mTvTbType.setBackgroundColor(ResUtils.getColor(R.color.white));
        }

        if(mListener != null){
            mTvTbType.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.itemClick(mAdapter, bean);
                }
            });
        }
    }
}
